/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.com.transportes.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import pe.com.transportes.modelo.Salidarutas;

/**
 *
 * @author z3phiroth
 */
public class SalidarutasDAO {


          public void insertarsalidas(Connection con,Salidarutas c) throws SQLException{

    String sql ="insert into salidarutas values (?,?,?,?,?,?,?)";
    PreparedStatement ps = con.prepareStatement(sql);


    System.out.println("codigo dao "+c.getCod_ruta());

    ps.setInt(1,c.getCod_salida());
     ps.setInt(2,c.getCod_asistente());
      ps.setInt(3,c.getCod_bus());
          ps.setInt(4,c.getCod_chofer());
          ps.setInt(5, c.getCod_ruta());
         ps.setString(6,c.getHorario());
       ps.setString(7, c.getFecha());



    ps.executeUpdate();
    }




public ArrayList<Salidarutas> buscarsalidas(Connection con,int cod_ruta,String fecha) throws SQLException{


    ArrayList<Salidarutas> lista =new ArrayList<Salidarutas>();

  String sql = "select * from salidarutas where cod_ruta=? and fecha=?";

        PreparedStatement ps = con.prepareStatement(sql);
        ps.setInt(1,cod_ruta);
         ps.setString(2,fecha);
          ResultSet rs = ps.executeQuery();
        while(rs.next()){
               Salidarutas bean = new Salidarutas();
                 bean.setCod_salida(rs.getInt(1));
                 bean.setCod_asistente(rs.getInt(2));
                   bean.setCod_bus(rs.getInt(3));
        bean.setCod_chofer(rs.getInt(4));
        bean.setCod_ruta(rs.getInt(5));
        bean.setHorario(rs.getString(6));
        bean.setFecha(rs.getString(7));

           lista.add(bean);


        }
        return lista;

}



public Salidarutas buscarsalidas2(Connection con,int cod_salida) throws SQLException{

System.out.println(cod_salida);
  String sql = "select * from salidarutas where cod_salida=?";

        PreparedStatement ps = con.prepareStatement(sql);
        ps.setInt(1,cod_salida);
        Salidarutas bean = new Salidarutas();
          ResultSet rs = ps.executeQuery();
      if(rs.next()){

                bean.setCod_salida(rs.getInt(1));
                 bean.setCod_asistente(rs.getInt(2));
                   bean.setCod_bus(rs.getInt(3));
        bean.setCod_chofer(rs.getInt(4));
        bean.setCod_ruta(rs.getInt(5));
        bean.setHorario(rs.getString(6));
        bean.setFecha(rs.getString(7));


        }
        return bean;

}
public ArrayList<Salidarutas> listadosalidadia(Connection con,String fecha) throws SQLException{


  String sql = "select * from salidarutas where fecha=?";
ArrayList<Salidarutas> lista = new ArrayList<Salidarutas>();
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setString(1,fecha);

          ResultSet rs = ps.executeQuery();
     while(rs.next()){
 Salidarutas bean = new Salidarutas();
                bean.setCod_salida(rs.getInt(1));
                 bean.setCod_asistente(rs.getInt(2));
                   bean.setCod_bus(rs.getInt(3));
        bean.setCod_chofer(rs.getInt(4));
        bean.setCod_ruta(rs.getInt(5));
        bean.setHorario(rs.getString(6));
        bean.setFecha(rs.getString(7));


        lista.add(bean);
        }
        return lista;

}

}
